import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
export default async function a002(fd: IFeidaoAiBrowserComponent) {
	const project_no = get(fd,'project_no');
	const risk_no = get(fd,'risk_no');
	const risk_status1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="risk_status"]');
	let risk_status;
	if ( risk_status1.value === "") {
		alert("请选择风险状态");
		return;
	} else {
	 risk_status = risk_status1.value;
	}
	const risk_type1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="risk_type"]');
	let risk_type ;
	if (risk_type1.value === "") {
		alert("请选择风险类型");
		return;
	} else {
		risk_type = risk_type1.value;
	}
	const involved_amount1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="involved_amount"]');
	const involved_amount = involved_amount1.value;
	if (!involved_amount) {
		alert("请填写涉及金额!");
		return;
	}
	if (!/^[0-9]*$/.test(involved_amount)) {
		alert("金额请输入数字!");
		return;
	}
	const risk_content1 = fd.data.node.querySelector<HTMLTextAreaElement>('[data-id="risk_content"]');
	const risk_content = risk_content1.value;
	if (!risk_content) {
		alert("请填写风险内容!");
		return;
	}
	const memo1 = fd.data.node.querySelector<HTMLTextAreaElement>('[data-id="memo"]');
	const memo = memo1.value;
	const res = await nodejs<{code: 0|1;result: string}>('risk-control/zj-000003/s002', {
		filter:{
			risk_no,
			project_no,
			risk_status,
			risk_type,
			involved_amount,
			risk_content,
			memo
		}
	});
	if (res.code === 1) {
		alert("修改成功");
		const xiu = fd.data.node.querySelector<HTMLDivElement>('[data-id="Xiu"]');
		set_node_cls(xiu, 'display-n', true);
		fire('zj-000001', 'a004');
		fire('zj-000001', 'a005');
	} else {
		alert("修改失败");
	}
}
